package com.skit.main.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.skit.common.bean.ApplyBean
import com.skit.main.R
import kotlinx.android.synthetic.main.main_apply_item.view.*

/**
 * @author shuike <a href="mailto:shuike007@gmail.com">Contact me.</a>
 * @version 1.0
 * @since  2020/6/4
 */
class ApplyManageAdapter(val applyBeans: MutableList<ApplyBean>) :
    RecyclerView.Adapter<ApplyManageAdapter.ViewHolder>() {

    var onItemClickListener: ((Int, ApplyBean) -> Unit)? = null

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.main_apply_item, parent, false)
        return ViewHolder(view).apply {
            itemView.setOnClickListener {
                onItemClickListener?.invoke(
                    bindingAdapterPosition,
                    applyBeans[bindingAdapterPosition]
                )
            }
        }
    }

    override fun getItemCount(): Int = applyBeans.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val applyBean = applyBeans[position]

        holder.itemView.name.text = applyBean.user.name
        holder.itemView.stuid.text = applyBean.user.userInfo.stuID.toString()
        when (applyBean.status) {
            0 -> {
                holder.itemView.tv.text = "待审核"
            }
            1 -> {
                holder.itemView.tv.text = "未通过"
            }
            2 -> {
                holder.itemView.tv.text = "已通过"
            }
            3 -> {
                holder.itemView.tv.text = "组织者"
            }
        }
    }
}